package com.atguigu.algorithm;

public class FindTheNumInArray {
    public static void main(String[] args) {
        int[][] a= new int[][]{
                {1,2,8,9},
                {2,4,9,12},
                {4,7,10,12},
                {6,8,11,15}
        };
        System.out.println(Find(7,a));
        System.out.println(Find(3,a));
    }
    public static boolean Find(int target,int[][] array){
        if(array==null || array.length==0){
            return false;
        }
        int row=array.length; //行数
        int col=array[0].length; //列数
        int x=0; // 行从第一行开始
        int y=col-1; //列从最后一列开始
        while(y>-1 && x<row){
            if(array[x][y]>target){
                y--;
            }else if(array[x][y]<target){
                x++;
            }else{
                return true;
            }
        }
        return false;
    }
}
